package cn.ibizlab.todo.core.pms.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.util.HashSet;
import java.util.HashMap;
import java.util.Collection;
import java.util.Objects;
import java.util.Optional;
import java.math.BigInteger;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.util.ObjectUtils;
import org.springframework.beans.factory.annotation.Value;
import cn.ibizlab.todo.util.errors.BadRequestAlertException;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.annotation.Lazy;
import cn.ibizlab.todo.core.pms.domain.User;
import cn.ibizlab.todo.core.pms.filter.UserSearchContext;
import cn.ibizlab.todo.core.pms.service.IUserService;

import cn.ibizlab.todo.util.helper.CachedBeanCopier;
import cn.ibizlab.todo.util.helper.DEFieldCacheMap;


import cn.ibizlab.todo.core.pms.client.UserFeignClient;

/**
 * 实体[用户] 服务对象接口实现
 */
@Slf4j
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    UserFeignClient userFeignClient;


    @Override
    public boolean create(User et) {
        User rt = userFeignClient.create(et);
        if(rt==null)
            return false;
        CachedBeanCopier.copy(rt,et);
        return true;
    }

    public void createBatch(List<User> list){
        userFeignClient.createBatch(list) ;
    }

    @Override
    public boolean update(User et) {
        User rt = userFeignClient.update(et.getId(),et);
        if(rt==null)
            return false;
        CachedBeanCopier.copy(rt,et);
        return true;

    }

    public void updateBatch(List<User> list){
        userFeignClient.updateBatch(list) ;
    }

    @Override
    public boolean remove(Long id) {
        boolean result=userFeignClient.remove(id) ;
        return result;
    }

    public void removeBatch(Collection<Long> idList){
        userFeignClient.removeBatch(idList);
    }

    @Override
    public User get(Long id) {
		User et=userFeignClient.get(id);
        if(et==null){
            et=new User();
            et.setId(id);
        }
        else{
        }
        return  et;
    }

    @Override
    public User getDraft(User et) {
        et=userFeignClient.getDraft();
        return et;
    }

    @Override
    public boolean checkKey(User et) {
        return userFeignClient.checkKey(et);
    }
    @Override
    @Transactional
    public boolean save(User et) {
        if(et.getId()==null) et.setId((Long)et.getDefaultKey(true));
        if(!userFeignClient.save(et))
            return false;
        return true;
    }

    @Override
    public void saveBatch(List<User> list) {
        userFeignClient.saveBatch(list) ;
    }





    /**
     * 查询集合 数据集
     */
    @Override
    public Page<User> searchDefault(UserSearchContext context) {
        Page<User> users=userFeignClient.searchDefault(context);
        return users;
    }

    /**
     * 查询集合 任务指派人员
     */
    @Override
    public Page<User> searchTaskTeam(UserSearchContext context) {
        Page<User> users=userFeignClient.searchTaskTeam(context);
        return users;
    }




}



